1. Class No.17 Data Structures http://ecomputernotes.com
2.
3.
4.
5.
6. Reference Variables // example 1 int intMinus1( int oldVal) { oldVal = oldVal – 1; return oldVal; } http://ecomputernotes.com
7. Reference Variables // example 2 int intMinus2( int* oldVal) { *oldVal = *oldVal – 2; return *oldVal; } http://ecomputernotes.com
8. Reference Variables // example 3 int intMinus3( int& oldVal) { oldVal = oldVal – 3; return oldVal; } http://ecomputernotes.com
9. Reference Variables The caller function: calling intMinus1 void caller() { int myInt = 31; int retVal; retVal = intMinus1( myInt ); cout << myInt << retVal; } http://ecomputernotes.com
10. Memory Organization Code Static data Stack Heap Process 1 (browser) Process 3 (word) Process 4 (ourtest.exe) Windows OS Process 2 (dev-c++) http://ecomputernotes.com
11.
12. Reference Variables Call stack layout when intMinus1 is called: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal 31 calling function “caller” called function “intMinus1” stack grows downwards sp
13.
14.
15. Reference Variables Call stack layout after subtraction in intMinus1: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal 31 calling function “caller” called function “intMinus1” stack grows downwards sp 30
16. Reference Variables Call stack layout after return from intMinus1: 1068 31 1072 30 caller’s other stuff myInt retVal calling function “caller” stack grows downwards sp
17.
18.
19. Reference Variables Call stack layout when intMinus2 is called: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal 1072 calling function “caller” called function “intMinus2” stack grows downwards sp
20. Reference Variables Call stack layout after *oldVal = *oldVal – 2; 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal 1072 calling function “caller” called function “intMinus2” stack grows downwards sp 29
21. Reference Variables Call stack layout after return from intMinus2. 1068 31 1072 29 caller’s other stuff myInt retVal calling function “caller” stack grows downwards sp 29
22.
23.
24.
25.
26. Reference Variables Call stack layout when intMinus3 is called: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal calling function “caller” called function “intMinus3” stack grows downwards sp
27. Reference Variables Call stack layout when intMinus3 is called: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal calling function “caller” called function “intMinus3” stack grows downwards sp
28. Reference Variables Call stack layout after oldVal = oldVal - 3: 1052 1060 1068 1056 31 1072 ? caller’s other stuff myInt retVal oldVal calling function “caller” called function “intMinus3” stack grows downwards sp 28
29. Reference Variables Call stack layout after return from intMinus3: 1068 31 1072 28 caller’s other stuff myInt retVal calling function “caller” stack grows downwards sp 28
30.
Editor's Notes
Start of lecture 17
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
End of lecture 2 The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.